package algotithm.leetcode.array.test80;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/6-9:32
 * @Title 80. 删除有序数组中的重复项 II
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,2,3,4,5,6};
        int i = solution.removeDuplicates(nums);
        System.out.println(i);
    }

    public int removeDuplicates(int[] nums) {
        int j = 1;
        int count = 1;
        for (int i = 1;i < nums.length; i++) {
            if (nums[i] == nums[i-1]) {
                count++;
            } else {
                count = 1;
            }
            if (count <= 2) {
                nums[j++] = nums[i];
            }
        }
        return j;
    }
}
